package cn.tedu.charging.account.dao.persist.repository.impl;

import cn.tedu.charging.account.dao.persist.mappers.OrderMapper;
import cn.tedu.charging.account.dao.persist.repository.IOrderRepository;
import cn.tedu.charging.account.pojo.entity.Order;
import cn.tedu.charging.account.pojo.vo.OrderStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
/**
 * 处理订单数据的存储库实现类
 *
 * @author wyy
 * @version 1.0
 */
@Slf4j
@Repository
public class OrderRepositoryImpl implements IOrderRepository {

    @Autowired
    private OrderMapper orderMapper;

    public OrderRepositoryImpl() {
        log.info("创建存储库对象：OrderRepositoryImpl");
    }

    @Override
    public int insert(Order order) {
        log.debug("开始执行【插入订单】的数据访问，参数：{}", order);
        return orderMapper.insert(order);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除订单】的数据访问，参数：{}", id);
        return orderMapper.deleteById(id);
    }

    @Override
    public int updateById(Order order) {
        log.debug("开始执行【更新订单】的数据访问，参数：{}", order);
        return orderMapper.updateById(order);
    }

    @Override
    public int countById(Long userId) {
        log.debug("开始执行【根据用户id统计订单的数量】的数据访问，参数：{}", userId);
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return orderMapper.selectCount(wrapper);
    }

    @Override
    public OrderStandardVO selectByDeviceId(Long id) {
        OrderStandardVO orderStandardVO = orderMapper.selectByDeviceId(id);
        return orderStandardVO;
    }
}
